package com.wxw.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import com.wxw.springcloud.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wxw
 * @data 2021/1/18 19 :48
 * @description
 */
@RestController
public class HelloController {


    @GetMapping(path = "/hello")
    public List hello(@RequestParam(value = "id", required = false) int id) {
        System.out.println(id);
        //业务逻辑，，，
        List list = new ArrayList<User>();
        User user = new User();
        User user1 = new User();
        user.setId(1);
        user.setName("陈嘉煌");
        user.setAge("女");
        user1.setId(2);
        user1.setName("陈礼杰");
        user1.setAge("🐕");
        list.add(user);
        list.add(user1);
        return list;
    }

    @GetMapping("/hystrix")
    @HystrixCommand(fallbackMethod = "hystrixGet")
    public String Hystrix() {
        //业务逻辑，，，
        //触发异常
        int a = 10 / 0;
        return "Hystrix1";
    }

    public String hystrixGet() {

        return "caonima";
    }
}
